
// 轮播
var mySwiper = new Swiper('.swiper', {
    speed: 2000,
    loop: true, // 循环模式选项
    autoplay: {   //自动切换
        delay: 2000,
    },
    loop: true, // 循环模式选项

    // 如果需要分页器
    pagination: {
        el: '.swiper-pagination',
    },

    // 如果需要前进后退按钮
    navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },
})

//首页数据
function banner_ajax() {
    $.ajax({
        type: 'get',
        url: 'http://www.xiongmaoyouxuan.com/api/tab/1',
        headers: { //url
            'x-platform': 'pc'
        },
        success: function (data) { //响应的参数
            banner_x(data.data.gridsV2)
            bannerA(data.data.banners)
            list(data.data.items.list)
        }
    })
}
banner_ajax()

//轮播图
function bannerA(itme) {
    $('.swiper_1>img').prop('src', itme[0].imageUrl)
    $('.swiper_2>img').prop('src', itme[1].imageUrl)
    $('.swiper_3>img').prop('src', itme[2].imageUrl)
}

//轮播小图
function banner_x(itme) {
    $('.right_1>p:nth-child(1)').html(itme[0].title)
    $('.right_1>p:nth-child(2)').html(itme[0].text)
    $('.right_1>img').prop('src', itme[0].imageUrl)
    $('.img_0>img').prop('src', itme[2].imageUrl)
    $('.img_0>p:nth-child(1)').html(itme[2].title)
    $('.img_0>p:nth-child(2)').html(itme[2].text)
    $('.img_1>img').prop('src', itme[1].imageUrl)
    $('.img_1>p:nth-child(1)').html(itme[1].title)
    $('.img_1>p:nth-child(2)').html(itme[1].text)
}

//更多商品列表数据
function moreAjax(num) {
    $.ajax({
        type: 'get',
        url: 'http://www.xiongmaoyouxuan.com/api/tab/1/feeds?start=20',
        data: {
            start: num * 20
        },
        success: function (data) { //响应的参数
            // console.log(data);
            list_more(data.data.list)
        }
    })
}
function btn_more() {
    let s = 0
    $('#morebtn>.btn').click(function () {
        s++
        moreAjax(s)
    })
}
btn_more()

//注册账户
$('.zhuce').click(function () {
    $('.register').css('display', 'block')
    $('.cover').css('display', 'block')
})
$('.denglu').click(function () {
    $('.Sign_1').css('display', 'block')
    $('.cover').css('display', 'block')
})
$('.no_1').click(function () {
    $('.register').css('display', 'none')
    $('.cover').css('display', 'none')
})
$('.no_2').click(function () {
    $('.Sign_1').css('display', 'none')
    $('.cover').css('display', 'none')
})

// 注册
function zhuce() {
    let yz = /\S{3,5}/
    let yz1 = /\w{6,10}/
    $('.text_1').blur(function () {
        let s1 = yz.test($('.text_1').val())
        if (!s1) {
            $('.p1_1').html('用户名需要3至5位')
        } else {
            $('.p1_1').html(' ')

        }
    })
    $('.password_1').blur(function () {
        let s2 = yz1.test($('.password_1').val())
        if (!s2) {
            $('.p1_2').html('密码需要6至10位,数字字母下划线组成')
        } else {
            $('.p1_2').html(' ')
        }
    })
    $('.yes_1').click(function () {
        let s1 = yz.test($('.text_1').val())
        if (!s1) {
            $('.p1_1').html('用户名需要3至5位')
        } else {
            $('.p1_1').html(' ')
        }
        let s2 = yz1.test($('.password_1').val())
        if (!s2) {
            $('.p1_2').html('密码需要6至10位,数字字母下划线组成')
        } else {
            $('.p1_2').html(' ')
        }
        if (s1 && s2) {
            let user = {
                username: $('.text_1').val(),
                password: $('.password_1').val()
            }
            let userStr = localStorage.getItem('xiongmao')
            let str_s1 = JSON.parse(userStr) || []
            str_s1.push(user)
            localStorage.setItem('xiongmao', JSON.stringify(str_s1))
            alert('注册成功')
            $('.register').css('display', 'none')
            $('.cover').css('display', 'none')
            $('.text_1').val('')
            $('.password_1').val('')
        }
    })

}

function denglu() {
    let yz = /\S{3,5}/
    let yz1 = /\w{6,10}/
    $('.text_2').blur(function () {
        let s1 = yz.test($('.text_2').val())
        if (!s1) {
            $('.p2_1').html('用户名需要3至5位')
        } else {
            $('.p2_1').html(' ')

        }
    })
    $('.password_2').blur(function () {
        let s2 = yz1.test($('.password_2').val())
        if (!s2) {
            $('.p2_2').html('密码需要6至10位,数字字母下划线组成')
        } else {
            $('.p2_2').html(' ')
        }
    })
    $('.yes_2').click(function () {
        let s1 = yz.test($('.text_2').val())
        if (!s1) {
            $('.p2_1').html('用户名需要3至5位')
        } else {
            $('.p2_1').html(' ')
        }
        let s2 = yz1.test($('.password_2').val())
        if (!s2) {
            $('.p2_2').html('密码需要6至10位,数字字母下划线组成')
        } else {
            $('.p2_2').html(' ')
        }
        if (s1 && s2) {
            let userStr = localStorage.getItem('xiongmao')
            let str_s1 = JSON.parse(userStr) || []
            let arrs = str_s1.find((itme) => itme.username == $('.text_2').val())
            if (arrs) {
                if (arrs.password == $('.password_2').val()) {
                    alert('登录成功')
                    $('.Sign1').html(arrs.username + '欢迎你')
                    $('.Sign_1').css('display', 'none')
                    $('.cover').css('display', 'none')
                    $('.password_2').val('')
                    
                    localStorage.setItem('name_x', `${$('.text_2').val()}欢迎你`)
                    $('.text_2').val('')
                    logoin()

                } else {
                    alert('密码错误')
                }
            } else {
                alert('用户名密码不正确')
            }
        }
    })
}
zhuce()
denglu()

//侧栏导航跳转

function sidebar() {
    $('#banner>.menu>ul>li').eq(0).click(function () {
        location.href = `list_1.html?id=2`
    })
    $('#banner>.menu>ul>li').eq(1).click(function () {
        location.href = `list_1.html?id=5`
    })
    $('#banner>.menu>ul>li').eq(2).click(function () {
        location.href = `list_1.html?id=24`
    })
    $('#banner>.menu>ul>li').eq(3).click(function () {
        location.href = `list_1.html?id=4`
    })
    $('#banner>.menu>ul>li').eq(4).click(function () {
        location.href = `list_1.html?id=10`
    })
    $('#banner>.menu>ul>li').eq(5).click(function () {
        location.href = `list_1.html?id=24`
    })
    $('#banner>.menu>ul>li').eq(6).click(function () {
        location.href = `list_1.html?id=6`
    })
    $('#banner>.menu>ul>li').eq(7).click(function () {
        location.href = `list_1.html?id=16`
    })
    $('#banner>.menu>ul>li').eq(8).click(function () {
        location.href = `list_1.html?id=7`
    })
}
sidebar()
